<template>
	<view class="back">
		<form @submit="formSubmit" @reset="formReset">
			<view class="one">
				<view class="add">
					<text class="a">推广类型</text>
				</view>
				<view class="jian">
					<radio-group @change="radioChange">
						<label  style="float: left;" class="free" v-for="(item, index) in tuiguang_type_list" :key="item.value">
							<view style="float: left;width: 50rpx;">
								<radio :value="item.value" :checked="index === tuiguang_type-1" />
							</view>
							<view  style="float: left;">{{item.name}}</view>
						</label>
					</radio-group>
				</view> 
			</view>
			<view class="one">
				<view class="add">
					<text class="a">推广单人单价</text>
				</view>
				<view class="jian">
					<input name="danjia"  type="number"   placeholder="每邀请一个好友的奖励" />
				</view>
			</view>
			<view class="one">
				<view class="add">
					<text class="a">总人数</text>
				</view>
				<view class="jian">
					<input name="jiangli_num"  type="number"   placeholder="一共有多少份奖励" />
				</view>
			</view>
			<button form-type="submit">确认发布</button>
		</form>
		
	</view>
</template>

<script>
	import urlsa from '../../../siteinfo.js';
	export default {
		data() {
			return {
				tuiguang_type_list:[
					{value:1,name:'现金'},
					{value:2,name:'积分'},
				],
				tuiguang_type:1,//推广类型
				type:'',// edit 为修改
				showcontent:false
			}
		},
		onLoad(o){
			
		},
		methods: {
			radioChange: function(evt) {
				for (let i = 0; i < this.tuiguang_type_list.length; i++) {
					if (this.tuiguang_type_list[i].value === evt.target.value) {
						this.tuiguang_type = this.tuiguang_type_list[i].value;
						console.log(this.tuiguang_type)
						break;
					}
				}
			},
			formSubmit: function(e) {
				console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))
				var formdata = e.detail.value
				if(!formdata.danjia){
					uni.showModal({
						title: '请填写单价'
					})
					return false
				}
				if(!formdata.jiangli_num){
				 	uni.showModal({
				 		title: '请填写奖励'
				 	})
				 	return false
				}
				this.global.request.post({//发布接口
					data: {
						do:'shangjia_manage',
						op:'tuiguang',
						top_num:'',
						jf_sum:'',
						danjia:formdata.danjia,
						jiangli_num:formdata.jiangli_num,
						tuiguang_type:this.tuiguang_type,
					},
					success: res => {
						uni.showToast({
							title: '发布成功',
						});
						if(this.tuiguang_type==1){
							//#ifdef H5
							this.global.request.pay_wx('do=pay&pay_type=shangjia_tuiguang&id='+res)
							//#endif
							//#ifdef MP-WEIXIN
							this.global.request.post({
								data: {
									id:res,
									pay_type:'shangjia_tuiguang',
									do:'wx_pay',
								},
								success: ress => {
									uni.requestPayment({
										'provider': 'wxpay',
										'timeStamp': ress.timeStamp,
										'nonceStr': ress.nonceStr,   //字符串随机数
										'package': ress.package,
										'signType': ress.signType,
										'paySign': ress.paySign,
										success: function (res) {
											uni.navigateTo({
												url: '/pagesA/fabu/manage'
											})
										}
									})
								}
							})
							//#endif
							}else{
							setTimeout(() => {
								uni.navigateTo({
									url: '/pagesA/fabu/manage'
								})
							}, 1000);
						}
					}
				})
			},
		}
	}
</script>

<style>
	button{
		margin: 30rpx;
		background-color: #2bbcff;
		color: white;
	}
	.free{
		color: #000000;
	}
	/* 底部 */
	.one1 {
		width: 674rpx;
		height: 120rpx;
		border-bottom: 1rpx solid #ccc;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.bao {
		width: 670rpx;
		padding-left: 40rpx;
		color: #9d9d9d;
	}
	
	
	
	.kuang {
		width: 180rpx;
		height: 180rpx;
		background: #e8e8e8;
		text-align: center;
		margin-top: 30rpx;
	}
	
	.photo {
		width: 200rpx;
		height: 200rpx;
		float: left;
	
	}
	
	.photo2 {
		width: 210rpx;
		height: 200rpx;
		float: left;
		
	
	}
	.jian {
		 display: flex;
		color: #949494;
		float: right;
	}
	
	.a {
		margin-right: 6px;
	}
	
	.jian input{
		
		margin-top: 40rpx;
		width: 320rpx;
		/* float: right; */
	}
	
	.add {
		width: 30%;
		/* display: flex;
		align-items: center; */
		
	}
	
	.img {
		width: 18px;
		height: 18px;
		margin-top: 20px;
	}
	
	.uni-steps {
		margin: 10px 0;
	}
	
	.grey {
		width: 100%;
		height: 8px;
		background: #dddddd;
	}
	
	.downfour {
		padding: 0 10px;
		background: #fff;
	}
	
	.one {
		padding: 0 20rpx;
		height: 60px;
		line-height: 60px;
		border-bottom: 1rpx solid #ccc;
		display: flex;
	}

	
	
	.back{
		width: 100%;
		/* height: 100vh; */
		background: #fff;
	}
	.choose_fl{
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		background-color: #fcf4d0;
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
	}
	.jiantou{
		width: 40rpx;
		height: 40rpx;
		margin-top: 20rpx;
	}
	.title_message{
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		background-color: #fff;
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
		
	}
	.title_message input{
		width: 70%;
		margin-top: 20rpx;
	}
	.xian{
		width: 100%;
		height: 1rpx;
		background: #ccc;
	}
	.textarea{
		width: 90%;
		height: 40rpx;
		background: #fff;
		min-height: 50rpx;
		line-height: 18px;
		/* border:1px solid #007AFF; */
		margin-top: 20rpx;
	
	}
	
	.detail_txt{
		height: auto;
		background: #fff;
		padding: 10rpx 30rpx;
		overflow: hidden;
	}
	</style>
